//
//  TFtouchesMoved.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/4/28.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TFtouchesMoved: UIView {

    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        let touch = touches.first!
        // 获取当前点
        let secondPoint = touch.location(in: self)
       // 获取上一个点
        let firstPoint = touch.previousLocation(in: self)

           //计算两点间的距离
            let offsetX:CGFloat = secondPoint.x - firstPoint.x
            let offsetY:CGFloat = secondPoint.y - firstPoint.y
            // 移动当前view
            if self.superview != nil {
                if (self.frame.origin.x+offsetX>0&&self.frame.origin.y+offsetY>0) {
                    
            if (self.frame.origin.y+offsetY<self.superview!.frame.size.height-self.frame.size.height&&self.frame.origin.x+offsetX<self.superview!.frame.size.width-self.frame.size.width) {
                        
                      
                            self.frame = CGRect(x: self.frame.origin.x+offsetX, y: self.frame.origin.y+offsetY, width: self.frame.size.width, height: self.frame.size.height)
                       
                    }
                    
                    
                }
        }
        
          
          
            
        
           
            
               
      

    
 
    }
  


}
